package cn.bonoon.kernel.web.models;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import cn.bonoon.kernel.support.models.Page;

/**
 * <pre>
 * DataGrid控件所需要的数据结构
 * </pre>
 * 
 * <pre>
 * 添加对footer的支持
 * </pre>
 * 
 * @author jackson
 * 
 */
public final class JsonPage implements Serializable {
	
	public final static JsonPage EMPTY = new JsonPage(0, Collections.emptyList());

	/**
	 * 
	 */
	private static final long serialVersionUID = 1399968199016814636L;

	public static JsonPage page(long total) {
		return new JsonPage(total, Collections.emptyList());
	}

	public static JsonPage page(Page page) {
		return new JsonPage(page.getTotal(), (List<Object>)page.getRows());
	}

	public static JsonPage page(long total, List<Object> rows) {
		return new JsonPage(total, rows);
	}

	public static JsonPage list(List<Object> rows) {
		return new JsonPage(rows.size(), rows);
	}

	private JsonPage(long total, List<Object> rows) {
		this.total = total;
		this.rows = rows;
	}

	private final long total;
	private final List<Object> rows;
	private List<Object> footer;
	
	public long getTotal() {
		return total;
	}

	public List<Object> getRows() {
		return rows;
	}
	
	public List<Object> getFooter() {
		return footer;
	}
}